<template>
	<view class="ikz-bid">
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<view>
			<ikz-login :show-data="loginData" :css-data="login_css"></ikz-login>
		</view>
		<view>
			<ikz-ordertop :order-number="number_info"></ikz-ordertop>
		</view>
		<view class="ikz-menu-box" v-if="user_openinfo.auth||!user_info">
			<view class="ikz-menu-title">接单员中心</view>
			<ikz-menu :show-data="menu_data1" :css-data="menu_css"></ikz-menu>
		</view>
		<view class="ikz-menu-box" v-if="user_openinfo.bind_agent_id||!user_info">
			<view class="ikz-menu-title">代理中心</view>
			<ikz-menu :show-data="menu_data2" :css-data="menu_css"></ikz-menu>
		</view>
		<view class="ikz-menu-box">
			<view class="ikz-menu-title">系统中心</view>
			<ikz-menu :show-data="menu_data" :css-data="menu_css"></ikz-menu>
		</view>
		<!-- 缺省 -->
		<view class="ikz-exit-but" @click="exitBut()" v-if="exitButTrue">退出登录</view>
		<!-- 备案号 -->
		<view class="main-statement" v-if="statement">备案号：{{ statement }}</view>
		<view class="default-height" style="width: 100%;height: 188rpx;"></view>
		<ikz-tabbar :show-data="tabbar_Data"></ikz-tabbar>
	</view>
</template>

<script>
	import ikzLoading from '@/pages/Component/Public/Loading/loading.vue';
	import ikzMenu from '@/pages/Component/Public/Menu/public/menu/menu.vue';
	import ikzLogin from '@/pages/Component/Public/Login/public/login/login.vue';
	import ikzOrdertop from '@/pages/Component/Public/Ordertop/public/ordertop/ordertop.vue';
	import ikzTabbar from '@/pages/Component/Public/tab-bar/tab-bar.vue';
	var app = getApp();
	import ikz from '@/pages/Common/tools.js';
	export default {
		components: {
			ikzLoading,
			ikzMenu,
			ikzLogin,
			ikzOrdertop,
			ikzTabbar
		},
		data() {
			return {
				exitButTrue:false,
				statement:"",
				tabbar_Data: {
					type: 0,
					list: []
				},
				user_openinfo: app.globalData.user_openinfo,
				user_info:"",
				loginData: {},
				login_css: {
					background_color: 'linear-gradient(to right,#F8C66D, #FBAB7E)',
					margin_top: 0,
					bg_border_radius: 0,
					width: 100
				},
				loading_css: {
					display: 'flex'
				},
				menu_data: {
					list: [{
							src: '/static/personal/about.png',
							title: '关于我们',
							url: {
								path: '/pages/Component/Module/Other/Program/about/index',
								info: '无功能',
								mode: '2'
							}
						},
						{
							src: '/static/personal/phone.png',
							title: '社区客服',
							url: {
								path: 'phone#' + app.globalData.customer_mobile,
								info: '无功能',
								mode: '5'
							}
						},
						{
							src: '/static/personal/wechat.png',
							title: '平台客服',
							url: {
								path: 'contact',
								info: '无功能',
								mode: '5'
							}
						},
						{
							src: '/static/personal/cooperation.png',
							title: '合作加盟',
							url: {
								path: 'phone#' + app.globalData.customer_mobile,
								info: '无功能',
								mode: '5'
							}
						},
						{
							src: '/static/personal/agree.png',
							title: '用户协议',
							url: {
								path: '/pages/Component/Module/Other/Program/agreement/index',
								info: '无功能',
								mode: '2'
							}
						},
						{
							src: '/static/personal/help.png',
							title: '帮助中心',
							url: {
								path: '/pages/Component/Module/Other/Program/help/index/index',
								info: '无功能',
								mode: '2'
							}
						},
						{
							src: '/static/personal/feedback.png',
							title: '意见反馈',
							url: {
								path: '/pages/Component/Module/Other/Program/feedback/index',
								info: '无功能',
								mode: '2'
							}
						},
						{
							src: '/static/personal/address.png',
							title: '地址管理',
							url: {
								path: '/pages/Component/Module/Address/Program/myAddress/index',
								info: 'token',
								mode: '2'
							}
						},
					]
				},
				menu_data1: {
					list: [{
							src: '/static/personal/receive.png',
							title: '接单员管理',
							url: {
								path: '/pages/Component/Module/Receiver/Program/home/index/index',
								info: 'token',
								mode: '2'
							}
						},
						{
							src: '/static/personal/price.png',
							title: '佣金提现',
							url: {
								path: '/pages/Component/Module/Payment/Program/withdrawal/index/index?status=2',
								info: 'token',
								mode: '2'
							}
						},
						{
							src: '/static/personal/order.png',
							title: '接单大厅',
							url: {
								path: '/pages/Component/Module/Receiver/Program/order/index/index',
								info: 'token',
								mode: '2'
							}
						},
						{
							src: '/static/personal/agree.png',
							title: '消息订阅',
							url: {
								path: '/pages/Personal/runSubscribe',
								info: 'token',
								mode: '2'
							}
						},
					]
				},
				menu_data2: {
					list: [{
							src: '/static/personal/about.png',
							title: '管理中心',
							url: {
								path: '/pages/Component/Module/Agent/Program/home/index/index',
								info: 'token',
								mode: '2'
							}
						},
						{
							src: '/static/personal/price.png',
							title: '佣金提现',
							url: {
								path: '/pages/Component/Module/Payment/Program/withdrawal/index/index?status=3',
								info: 'token',
								mode: '2'
							}
						},
						{
							src: '/static/personal/agree.png',
							title: '消息订阅',
							url: {
								path: '/pages/Personal/agentSubscribe',
								info: 'token',
								mode: '2'
							}
						}
					]
				},
				menu_css: {
					background_color: '#fff',
					bg_border_radius: 0,
					border_radius: '50%',
					color: '#888888',
					margin_top: 15,
					num: '4',
					width: 100
				},
				number_info: {},
				run_apply_status: '',
			};
		},
		created() {
			// var that = this; 
		},
		onLoad() {
			uni.hideTabBar()
		},
		onShow() {
			this.user_info = uni.getStorageSync("user_info")
			this.tabbar_Data.list = app.globalData.tabBarInfo
			this.tabbar_Data.type =  app.globalData.tabBarInfo.length - 1
			this.goApplyPhone();
			if(!uni.getStorageSync("user_info")) {
				this.loading_css.display = 'none';
				return
			}
			this.loginData.user_openinfo = uni.getStorageSync("user_info")
			this.loginData.mobile = app.globalData.mobile || uni.getStorageSync("user_info").mobile
			this.userAuth((res) => {
				this.loading_css.display = 'none';
			});
			this.orderNumber();
			if(uni.getStorageSync('local_user_session')){
				this.exitButTrue = true
				this.getBaseinfo()
			}else{
				this.exitButTrue = false
			}
		},
		onPullDownRefresh() {
			this.goApplyPhone();
			if(!uni.getStorageSync("user_info")) {
				uni.stopPullDownRefresh();
				return
			}
			this.orderNumber();
			this.userAuth((res) => {
				uni.stopPullDownRefresh();
			});
		},
		onShareTimeline() {

		},
		onShareAppMessage() {
			// const promise = new Promise(resolve => {
			//   setTimeout(() => {
			//     resolve({ 
			//       title: '自定义转发标题',
			//       imageUrl:'https://xybaddon.maiwd.cn/shareButton.png',
			//     }) 
			//   }, 2000)
			// }) 
			return {
				title: app.globalData.share_info.share_title,
				path: '/pages/Home/index',
				imageUrl: app.globalData.share_info.share_img,
			}
		},
		methods: {
			//获取用户信息
			getBaseinfo() {
				var path = '/xyb/user/baseinfo';
				var data = {
					token: uni.getStorageSync('local_user_session'),
					app_plat: "MP-WEIXIN"
				};
				ikz.get(path, data, res => {
					if (res.data.code) {
						console.log("值是", res.data.data);
						this.statement = res.data.data.applet_record_number
						var user_address = res.data.data.user_address_list
						if (user_address.length) {
							getApp().globalData.user_address.address_all = ''; //地址数据
			
							getApp().globalData.user_address.address_all = user_address; //地址数据
							for (var i = 0; i < user_address.length; i++) {
								if (user_address[i].defaults) {
									getApp().globalData.user_address.address_default = user_address[i]; //默认地址
									getApp().globalData.user_address.address_current = user_address[i]; //当前
								}
							}
							if (getApp().globalData.user_address.address_default == '') {
								getApp().globalData.user_address.address_default = user_address[0]; //默认地址
								getApp().globalData.user_address.address_current = user_address[0]; //当前
							}
						} else {
							getApp().globalData.user_address.address_all = ''; //地址数据
							getApp().globalData.user_address.address_default = ''; //默认地址
							getApp().globalData.user_address.address_current = ''; //当前
						}
			
						//设置用户信息
						if (res.data.data.user_info.nickname) {
							getApp().globalData.user_openinfo = res.data.data.user_info || {};
						} else {
							getApp().globalData.user_openinfo = {};
						}
			
			
			
					}
			
				});
			},
			goApplyPhone() {
				var path = '/xyb/agent/phone';
				var data = {}
				if(uni.getStorageSync('local_user_session')){
					ikz.post(path, data, res => {
						if (res.data.code) {
							this.menu_data.list[1].url.path = 'phone#' + (res.data.data && res.data.data.phone)||'',
								this.$forceUpdate();
						} else {
							uni.showModal({
								title: '提示',
								content: res.data.msg,
								showCancel: false,
								success: function(res) {}
							});
						}
					});
				}
			
			},
			orderNumber() {
				var path = '/xyb/user/center_order_count';
				var data = {}
				ikz.post(path, data, res => {
					if (res.data.code) {
						this.number_info = res.data.data;
						this.$forceUpdate();
					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function(res) {}
						});
					}
				});

			},
			// 退出登录 
			exitBut() {
				uni.showModal({
					title: "系统提示",
					content: "确定要退出登录吗？",
					confirmColor: "#F8C66D",
					success: (res) => {
						if (res.confirm) {
							var path = '/user/logout';
							var data = {}
							ikz.post(path, data, res => {
								if (res.data.code) {
									uni.removeStorageSync("local_user_session")
									uni.removeStorageSync("user_info")
									uni.reLaunch({
										url:"/pages/Personal/index"
									})
								} else {
									uni.showModal({
										title: '提示',
										content: res.data.msg,
										showCancel: false,
										success: function(res) {}
									});
								}
							});
							
						}
					}
				})
			},
			goApply() {
				var path = '/pages/Component/Module/Receiver/Program/apply/index/index';
				ikz.nav(path, 'n', '');
			},
			//请求页面数据
			userAuth(fn) {
				var path = '/xyb/user/auth';
				var data = {};
				ikz.post(path, data, res => {
					if (res.data.code) {
						this.user_openinfo.auth = res.data.data.auth;
						this.user_openinfo.bind_agent_id = res.data.data.bind_agent_id;
						this.user_openinfo.run_apply_status = res.data.data.run_apply_status;
					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function(res) {}
						});
					}
					fn();
					// if(that.pull_status){
					// 	this.$emit("change",'pull');
					// } 
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.ikz-bid {
		width: 100%;
		height: 100%;
		background: #F3F3F3;
		min-height: 100vh;
	}

	.ikz-menu-title {
		position: relative;
		box-sizing: border-box;
		width: 100%;
		padding: 0px 30rpx 10px 50rpx;
		font-weight: 800;
	}

	.ikz-menu-title:before {
		content: " ";
		display: inline-block;
		height: 40rpx;
		width: 10rpx;
		background: #FBAB7E;
		border-radius: 15rpx;
		position: absolute;
		left: 30rpx;
		top: 0px
	}

	.ikz-menu-box {
		box-sizing: border-box;
		padding: 30rpx 0px 30rpx;
		width: 95%;
		margin: 20rpx auto 0px;
		background: #fff;
		border-radius: 15rpx;
		overflow: hidden;
	}
	
	.ikz-exit-but{
		padding: 28rpx 0px 28rpx;
		margin: 20rpx auto 0px;
		// background:linear-gradient(to right,#F8C66D, #FBAB7E);
		background: #fff;
		color: #FBAB7E;
		width: 95%;
		border-radius: 15rpx;
		text-align: center;
		font-size: 32rpx;
	}
	
	
	.main-statement {
		font-size: 24rpx;
		line-height: 34rpx;
		color: #8d929c;
		margin-top: 48rpx;
		text-align: center;
	}
</style>
